<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
                <label class="el-form-item-label">产品SN</label>
                <el-input v-model="query.productSn" clearable placeholder="产品SN" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                <label class="el-form-item-label">产品型号</label>
                <el-input v-model="query.productCode" clearable placeholder="产品型号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                <label class="el-form-item-label">产品类型</label>
                <el-input v-model="query.productType" clearable placeholder="产品类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                <label class="el-form-item-label">工序编码</label>
                <el-input v-model="query.operationCode" clearable placeholder="工序编码" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                <label class="el-form-item-label">工序名称</label>
                <el-input v-model="query.operationName" clearable placeholder="工序名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                <label class="el-form-item-label">执行顺序</label>
                <el-input v-model="query.executionOrder" clearable placeholder="执行顺序" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                <label class="el-form-item-label">上工序编号</label>
                <el-input v-model="query.upStationCode" clearable placeholder="上工序编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                <label class="el-form-item-label">下工序编号</label>
                <el-input v-model="query.nextStationCode" clearable placeholder="下工序编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
                  <el-select v-model="query.isCheck" clearable filterable
                             placeholder="请选择" style="width: 185px;" class="filter-item" @change="crud.toQuery" >
                    <el-option
                            v-for="item in dict.whether"
                            :key="item.id"
                            :label="item.label"
                            :value="item.value" />
                  </el-select>
                  未设置字典，请手动设置 Select
                  <el-select v-model="query.result" clearable filterable
                             placeholder="请选择" style="width: 185px;" class="filter-item" @change="crud.toQuery" >
                    <el-option
                            v-for="item in dict.result"
                            :key="item.id"
                            :label="item.label"
                            :value="item.value" />
                  </el-select>
                  <el-select v-model="query.repairSign" clearable filterable
                             placeholder="请选择" style="width: 185px;" class="filter-item" @change="crud.toQuery" >
                    <el-option
                            v-for="item in dict.result_status"
                            :key="item.id"
                            :label="item.label"
                            :value="item.value" />
                  </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="产品SN" prop="productSn">
            <el-input v-model="form.productSn" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="产品型号" prop="productCode">
            <el-input v-model="form.productCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="产品类型" prop="productType">
            <el-input v-model="form.productType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="工序编码" prop="operationCode">
            <el-input v-model="form.operationCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="工序名称" prop="operationName">
            <el-input v-model="form.operationName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="执行顺序" prop="executionOrder">
            <el-input v-model="form.executionOrder" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="上工序编号" prop="upStationCode">
            <el-input v-model="form.upStationCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="下工序编号" prop="nextStationCode">
            <el-input v-model="form.nextStationCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否校验" prop="isCheck">
            <el-select v-model="form.isCheck" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.whether"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="是否屏蔽" prop="isShield">
            未设置字典，请手动设置 Select
          </el-form-item>
          <el-form-item label="当前工序结果" prop="result">
            <el-select v-model="form.result" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.result"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="返修标识" prop="repairSign">
            <el-select v-model="form.repairSign" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.result_status"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="创建人">
            <el-input v-model="form.createBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新人">
            <el-input v-model="form.updateBy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间">
            <el-input v-model="form.updateTime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="productSn" label="产品SN" />
        <el-table-column prop="productCode" label="产品型号" />
        <el-table-column prop="productType" label="产品类型" />
        <el-table-column prop="operationCode" label="工序编码" />
        <el-table-column prop="operationName" label="工序名称" />
        <el-table-column prop="executionOrder" label="执行顺序" />
        <el-table-column prop="upStationCode" label="上工序编号" />
        <el-table-column prop="nextStationCode" label="下工序编号" />
        <el-table-column prop="isCheck" label="是否校验">
          <template slot-scope="scope">
            {{ dict.label.whether[scope.row.isCheck] }}
          </template>
        </el-table-column>
        <el-table-column prop="isShield" label="是否屏蔽" />
        <el-table-column prop="result" label="当前工序结果">
          <template slot-scope="scope">
            {{ dict.label.result[scope.row.result] }}
          </template>
        </el-table-column>
        <el-table-column prop="repairSign" label="返修标识">
          <template slot-scope="scope">
            {{ dict.label.result_status[scope.row.repairSign] }}
          </template>
        </el-table-column>
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateBy" label="更新人" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column v-if="checkPer(['admin','dataProductPath:edit','dataProductPath:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDataProductPath from '@/api/data/dataProductPath'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, productSn: null, productCode: null, productType: null, operationCode: null, operationName: null, executionOrder: null, upStationCode: null, nextStationCode: null, isCheck: null, isShield: null, result: null, repairSign: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
  name: 'DataProductPath',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['whether', 'result', 'result_status'],
  cruds() {
    return CRUD({ title: '产品工艺路线', url: 'api/dataProductPath', idField: 'id', sort: 'id,desc', crudMethod: { ...crudDataProductPath }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'dataProductPath:add'],
        edit: ['admin', 'dataProductPath:edit'],
        del: ['admin', 'dataProductPath:del']
      },
      rules: {
        productSn: [
          { required: true, message: '产品SN不能为空', trigger: 'blur' }
        ],
        productCode: [
          { required: true, message: '产品型号不能为空', trigger: 'blur' }
        ],
        productType: [
          { required: true, message: '产品类型不能为空', trigger: 'blur' }
        ],
        operationCode: [
          { required: true, message: '工序编码不能为空', trigger: 'blur' }
        ],
        operationName: [
          { required: true, message: '工序名称不能为空', trigger: 'blur' }
        ],
        executionOrder: [
          { required: true, message: '执行顺序不能为空', trigger: 'blur' }
        ],
        upStationCode: [
          { required: true, message: '上工序编号不能为空', trigger: 'blur' }
        ],
        nextStationCode: [
          { required: true, message: '下工序编号不能为空', trigger: 'blur' }
        ],
        isCheck: [
          { required: true, message: '是否校验不能为空', trigger: 'blur' }
        ],
        isShield: [
          { required: true, message: '是否屏蔽不能为空', trigger: 'blur' }
        ],
        result: [
          { required: true, message: '当前工序结果不能为空', trigger: 'blur' }
        ],
        repairSign: [
          { required: true, message: '返修标识不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'productSn', display_name: '产品SN' },
        { key: 'productCode', display_name: '产品型号' },
        { key: 'productType', display_name: '产品类型' },
        { key: 'operationCode', display_name: '工序编码' },
        { key: 'operationName', display_name: '工序名称' },
        { key: 'executionOrder', display_name: '执行顺序' },
        { key: 'upStationCode', display_name: '上工序编号' },
        { key: 'nextStationCode', display_name: '下工序编号' },
        { key: 'isCheck', display_name: '是否校验' },
        { key: 'isShield', display_name: '是否屏蔽' },
        { key: 'result', display_name: '当前工序结果' },
        { key: 'repairSign', display_name: '返修标识' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
